import { login } from '@/services/UserController';
import { PageContainer } from '@ant-design/pro-components';
import { history, useSearchParams } from '@umijs/max';
import { useEffect } from 'react';

export default () => {
    const [params] = useSearchParams();
    const appId = 'wxb6498f9c5309eba3';
    const redirectUri = 'http://coupon.teamwork.ink/jump';
    const responseType = 'code';
    const scope = 'snsapi_userinfo';
    const state = 'STATE';
    const api = 'https://open.weixin.qq.com/connect/oauth2/authorize';
    const url = `${api}?appid=${appId}&redirect_uri=${redirectUri}&response_type=${responseType}&scope=${scope}&state=${state}#wechat_redirect`;

    const code = 'abc'; //params.get('code');
    useEffect(() => {
        if (code) {
            login({ code }).then((res) => {
                localStorage.setItem('token', res.token);
                history.push('/');
            });
        } else {
            window.location.href = url;
        }
    });
    return <PageContainer>{code}</PageContainer>;
};
